// components/classSearch/search.js
import utils from '../../utils/util.js'
import { config } from '../../utils/config'
Component({
  /**
   * Component properties
   */
  properties: {
    searchObj : Object
  },

  /**
   * Component initial data
   */
  data: {
    imgUrl: config.imgUrl,
    searchTip: false,
    inputValue : ''
  },

  lifetimes: {
    attached(){
     
    }
  },

  /**
   * Component methods
   */
  methods: {
     /**/
     searchTip() {
      if (this.data.inputValue) {
          this.setData({
              searchTip: true
          })
      } else {
          this.setData({
              searchTip: !this.data.searchTip
          })
      }

  },
  /*搜索失去焦点*/
  inputBlur() {
    setTimeout(() => {
      if (this.data.inputValue) {
        this.setData({
            searchTip: true
          })
      } else {
          this.setData({
              searchTip: false
          })
      }
    }, 100);
      
  },
  /*搜索*/
  searchInput: function(e) {
    // console.log(e);
    let inputValue = e.detail.value;

    if (inputValue) {
        this.setData({
            inputValue,
            deleteBtn: true
        })
    }else{
      this.setData({
        deleteBtn: false,
    })
    }
  },
  /*删除搜索框内容  searchTip true隐藏  false显示*/
  deleteSearch() {
      console.log(1);
      setTimeout(() => {
        this.setData({
          inputValue: '',
          deleteBtn: false,
          searchTip: false
        })
      }, 0);
  },
  /*搜索按钮*/
  searchHandle() {
      this.setData({
          searchTip: true
      })
      if (this.data.inputValue == '') {
          wx.showToast({
              title: '请输入关键词',
              icon: 'none',
              duration: 1500
          })
          return;
      }
      /* categoryActive 1菜品   2菜谱    */
      this.triggerEvent('searchHandleBtn', { inputValue: this.data.inputValue });

  },
  }
})
